package com.example.gz_android_firstgroup;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.annotation.Nullable;

public class WelcomeActivity extends Activity {
    ImageView img_welcome;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        宣布布局
        setContentView(R.layout.welcomeactivity);
        //隐藏标题栏以及状态栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //找到执行动画
        img_welcome = findViewById(R.id.ivMainWelcone);
        //创建动画--->ObjectAnimator动画对象
        //参数一,执行动画.参数二,动画类型.参数三,开始结束位置
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(img_welcome, "alpha", 0.2f, 1.0f);
        //渐变时间
        objectAnimator.setDuration(3000);
        //启动
        objectAnimator.start();
        objectAnimator.addListener(new AnimatorListenerAdapter() {
            //这里面只选择一个onAnimationEnd执行完成,
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
            }
        });
    }

    @Override
    protected void onRestart() {
//        重开的时候直接跳 不走图片那
        startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
        super.onRestart();
    }

    @Override
    protected void onStop() {
//        关闭的时候直接 销毁这个atvt
        finish();
        super.onStop();
    }
}